// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import * as auth from 'utils/auth'
import config from './utils/config'
import { post, fetch, patch, put } from 'services/index'
//定义全局变量
Vue.prototype.$post = post;
Vue.prototype.$fetch = fetch;
Vue.prototype.$patch = patch;
Vue.prototype.$put = put;

Vue.config.productionTip = false

// import Vant from 'vant';
import 'vant/lib/vant-css/index.css';
// Vue.use(Vant);
import { Toast, Dialog, Tab, Tabs, Popup, Picker, Field, Button, List } from 'vant';
Vue.use(Toast).use(Dialog).use(Picker).use(Popup)
Vue.use(Tab).use(Tabs)
Vue.use(Field).use(Button);
Vue.use(List)

// 设置html字体大小
document.documentElement.style.fontSize = window.innerWidth / 21.6 + 'px'

// 定义全局变量
window.xmview = {
    showAlert(title = '', content, confirmText = '确认', fn) {
        Dialog.alert({
            title: title,
            message: content,
            confirmButtonText: confirmText
        }).then(() => {
            // on close
            fn()
        });
    },
    showToast(msg) {
        Toast(msg);
    },
    showLoading(msg) {
        Toast.loading({
            duration: 0,
            mask: true,
            message: msg
        });
    },
    hideLoading() {
        Toast.clear();
    },

    // auth.js 加密key
    getKey(url = 'detail-comment', unionid) {
        let baseUrl = config.API_YI

        return new Promise(function(resolve, reject) {
            let haskeyurl = auth.yjsb_auth(`${baseUrl}/v1/${url}`, unionid)
                // https://api.yjsb18.xyz/v1/detail-comment?unionid=oc6KSw1HM0AxFtzuftDs5c2YH0ZU&key=7dd4734996ee1d703ac5995b0512569e
            resolve(haskeyurl.split("key=")[1]);
        });
    }

}
window.xmrouter = router
window.xmconfig = {
    API_NC: config.API_NC,
    API_YI: config.API_YI,
    Index_url: config.Index_url,
    AUTH_URL: config.AUTH_URL,
    XC_URL: config.XC_URL
}

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    render: h => h(App)
})

export default {}